package atom.core0.util;

import java.text.DecimalFormat;

public class NumberUtil
{
	//如果d 为-.00005,则现在成了-.00 应该是.00
	public static String getFormatStr(Double d, int precision)
	{
		String formatStr = "#";
		if (precision > 0)
			formatStr += ".";
		for (int i = 0; i < precision; i++)
			formatStr += "0";

		DecimalFormat df = new DecimalFormat(formatStr);// "#.00"
		String sReturn = df.format(d);
		if (sReturn.startsWith("-."))
		{
			String sLeft = sReturn.substring(2);
			int nLeft = Integer.valueOf(sLeft);
			if (nLeft==0)
				sReturn = "."+sLeft;
		}
		return sReturn;
	}

}
